package com.luck.easyfoodbatch.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.TextView;

import com.luck.easyfoodbatch.R;

/**
 * 自定义透明的dialog
 */
public class ShowProgressDialog extends Dialog {
    private String content;

    public ShowProgressDialog(Context context) {
        super(context, R.style.ProgressDialog);
        initView();
    }

    public void setContent(String content) {
        this.content = content;
        ((TextView) findViewById(R.id.tvcontent)).setText(content);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (ShowProgressDialog.this.isShowing())
                    ShowProgressDialog.this.dismiss();
                break;
        }
        return true;
    }

    private void initView() {
        setContentView(R.layout.dialog_view);
        setCanceledOnTouchOutside(false);
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.alpha = 0.9f;
        getWindow().setAttributes(attributes);
        setCancelable(false);
    }
}